package com.swt.controller.T_controller;

import com.alibaba.fastjson.JSON;
import com.swt.domain.Club;
import com.swt.domain.Member;
import com.swt.service.T_service.MemberService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Controller
public class MemberController {
    @Resource(name = "TMemberService")
    private MemberService memberService;

    //会员卡添加
    @RequestMapping("/memberAdd")
    @ResponseBody
    public String memberAdd(Member member, HttpServletRequest httpServletRequest){
        Club club = (Club) httpServletRequest.getSession().getAttribute("CLUB_SESSION_KEY");
        int clubClubId = club.getClubId();
        System.out.println(member);

        boolean add  = memberService.memberAdd(member,clubClubId);
        return JSON.toJSONString(add);
    }
    //会员卡查询
    @RequestMapping("/memberQuery")
    @ResponseBody
    public String memberQuery(HttpServletRequest httpServletRequest){
        Club club = (Club) httpServletRequest.getSession().getAttribute("CLUB_SESSION_KEY");
        int clubClubId = club.getClubId();
        List<Member> list = memberService.memberQuery(clubClubId);
        return JSON.toJSONString(list);
    }
    //会员卡删除
    @RequestMapping("/deleteMember")
    @ResponseBody
    public String memberDelete(int id){
        boolean memberDelete=  memberService.memberDelete(id);
        return JSON.toJSONString(memberDelete);
    }
    //会员卡查询根据id
    @RequestMapping("/memberQuery2")
    @ResponseBody
    public String memberQuery2(int id){
        List<Member> list = memberService.memberQuery2(id);
        return JSON.toJSONString(list);
    }
//会员卡修改
    @RequestMapping("/memberUpdate")
    @ResponseBody
    public String memberUpdate(Member member){

        boolean memberUpdate = memberService.memberUpdate(member);
        return JSON.toJSONString(memberUpdate);
    }










//    //字符截取组合成数组方法
//    public String [] arr(String coursesid){
//
//        String  coursesid1 = coursesid.substring(1);
//        coursesid1 = coursesid1.substring(0,coursesid1.length()-1);
//        String[] strs=coursesid1.split(",");
//
//        String[] ints = new String[strs.length];
//        for(int i=0;i<strs.length;i++){
//            String sds = strs[i];
//            System.out.println(sds.length());
//            sds=sds.substring(1);
//            sds= sds.substring(0,sds.length()-1);
//            ints[i] = sds;
//        }
//
//        System.out.println(ints);
//        return ints;
//
//    }

    public MemberService getMemberService() {
        return memberService;
    }

    public void setMemberService(MemberService memberService) {
        this.memberService = memberService;
    }
}
